# -*- coding: utf-8 -*-
import os
import signal

from PySide2 import QtGui
from PySide2.QtWidgets import QApplication
from NodeGraphQt import constants, NodeGraph
from common import Common





if __name__ == '__main__':
    # handle SIGINT to make the app terminate on CTRL+C
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    app = QApplication([])
    icon = QtGui.QIcon()
    icon.addPixmap(QtGui.QPixmap("doc/logo.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
    app.setWindowIcon(icon)
    app.setApplicationName("大数据处理平台")

    # create graph controller.
    graph = NodeGraph()
    graph.set_background_color(202, 230, 202)
    graph.set_grid_mode(constants.ViewerEnum.GRID_DISPLAY_NONE.value)
    graph.set_pipe_style(constants.PipeLayoutEnum.STRAIGHT.value)

    # set up context menu for the node graph.
    graph.set_context_menu_from_file('../test2/hotkeys/hotkeys.json')

    Common.reload_script(graph)


    def show_node_dialog(node):
        node.show(True)


    # wire function to "node_double_clicked" signal.
    graph.node_double_clicked.connect(show_node_dialog)

    # show the node graph widget.
    graph_widget = graph.widget
    graph_widget.resize(1100, 800)
    graph_widget.show()

    # auto layout nodes.
    graph.auto_layout_nodes()

    app.exec_()
